package com.snow.storeapi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.snow.storeapi.entity.Checked;
import com.snow.storeapi.entity.StackCatalog;
import com.snow.storeapi.entity.StackContent;
import com.snow.storeapi.service.ICheckedService;
import com.snow.storeapi.service.IStackCatalogService;
import com.snow.storeapi.service.IStackContentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkout")
public class CheckoutController {
    private static final Logger logger = LoggerFactory.getLogger(VipController.class);

    @Autowired
    private IStackCatalogService stackCatalogService;

    @Autowired
    private IStackContentService stackContentService;

    @Autowired
    private ICheckedService checkedService;

    @GetMapping("/catalog/{checkingOrTesting}")
    public List<StackCatalog> catalog(@PathVariable String checkingOrTesting) {
        List<StackCatalog> stackCatalogs;
        QueryWrapper queryWrapper;
        if ("checking".equals(checkingOrTesting)) {
            queryWrapper = new QueryWrapper<StackCatalog>().eq("stack_type", "JCXM-PACS").orderByAsc("stack_code");
        } else if ("testing".equals(checkingOrTesting)) {
            queryWrapper = new QueryWrapper<StackCatalog>().eq("stack_type", "JYXM-LIS").orderByAsc("stack_code");
        } else {
            return null;
        }
        stackCatalogs = stackCatalogService.list(queryWrapper);
        return stackCatalogs;
    }
    @PostMapping("/content")
    public List<StackContent> content(@RequestBody List<String> stackCodes) {
        if (stackCodes.size() > 0) {
            List<StackContent> stackContents = stackContentService.list(new QueryWrapper<StackContent>().in("stack_code", stackCodes).orderByAsc("stack_code"));
            return stackContents;
        } else {
            return null;
        }
    }
    @GetMapping("/checked/{recordId}")
    public List<Checked> getChecked(@PathVariable String recordId) {
        List<Checked> checkeds = checkedService.list(new QueryWrapper<Checked>().eq("use_state", "1").eq("record_id", recordId));
        return checkeds;
    }

}
